<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <include file="./Application/Admin/View/block/amap_header.php" />
    <link href="__PUBLIC__/css/Content/index.css" rel="stylesheet" type="text/css" />
    <style>
        #dg{
            height: 100%;;
        }
    </style>
    <script>
        $(function(){
            $('#rivergateTree').tree({
                method: 'get',
                checkbox : false,
                lines: true,
                url : '__URL__/get_river_gate_tree',
                checkbox:true,
                onLoadSuccess: function (node, data) {
                    //$('#tabs_rivergate').tabs({height:600,width:960});
                    $('#tabs_gate').tabs({height:$('#subTabCtrl_1').height()-40,width:$('#subTabCtrl_1').width()-50});

                    var firstLeaf=null;
                    if($('#rivergate_id').val()=="")
                        firstLeaf = getFirstLeafNode();
                    else
                        firstLeaf=$('#rivergateTree').tree('find', parseInt($('#rivergate_id').val()));

                    $('#rivergateTree').tree('select',firstLeaf.target);

                    var id = firstLeaf.id;
//                    switchTreeNode(id);
                    $(".validatebox-tip").remove();
                    $('#btnList').linkbutton('enable');

                    $('#btnList').linkbutton('enable');
                    $('#tabs_gate').tabs('resize');
                }
            });

        });

        function getFirstLeafNode() {
            var node = $('#rivergateTree').tree('getRoot');
            var children=null;
            while(!$('#rivergateTree').tree('isLeaf', node.target)) {
                if (node){
                    children = $('#rivergateTree').tree('getChildren', node.target);
                } else {
                    children = $('#rivergateTree').tree('getChildren');
                }
                if (children!=null && children.length>0)
                    node = children[0];
            }
            return node;
        }

        function switchTreeNode() {
            var s = getChecked();
            if(s==''){
                $.messager.show({title:'提示',msg:'请勾选需要导出的调蓄池',showType:'slide'});
                return;
            }
            $('#rivergate_id').val(s);
            //清空所有form
            $('form').form('clear');
            $("input[name='gateid']").val(s);
            $("input[name='ischecked']").val(1);
            //刷新说有表格
            $('#grid_gate').datagrid({queryParams:{'gateid':$('#rivergate_id').val(),page:1,rows:10}});
            $('#grid_gate_log').datagrid({queryParams:{'gateid':$('#rivergate_id').val(),'ischecked':1,page:1,rows:10}});
            $('#grid_weather_log').datagrid({queryParams:{'facilities_type':3,'facilities_id':$('#rivergate_id').val(),page:1,rows:20}});
            //刷新需要的控件
            $('.gate_select').combobox('reload','/Manage/AdminGate/get_all_gate');


            editRivergate($('#rivergate_id').val());
        }

        function export_xls(){
            if(getChecked()==''){
                $.messager.show({title:'提示',msg:'请勾选需要导出的河道闸门',showType:'slide'});
                return;
            }
            $('#gtx_window').window('open');
        }

        function bz_xls(){
            var s = getChecked();
            if(s==''){
                $.messager.show({title:'提示',msg:'请勾选需要导出的河道闸门',showType:'slide'});
                return;
            }
            $('#zb_window').window('open');
        }

        function getChecked(){
            var nodes = $('#rivergateTree').tree('getChecked');
            var s = '';
            for(var i=0; i<nodes.length; i++){
                if (!$('#rivergateTree').tree('isLeaf', nodes[i].target)||isNaN(nodes[i].id)) {
                    continue;
                }
                if (s != '') s += ',';
                s += nodes[i].id;
            }
            return s;
        }
    </script>
</block>
<block name="bdoy">
    <body>
    <input type="hidden" id="dsfg" name="dsfg" value="dsfg"/>
    <input type="hidden" id="rivergate_id" name="rivergate_id"/>
    <div class="easyui-layout" style="width:100%;height: 500px;"  fit="true">
        <div data-options="region:'west',split:true" title="{:LANG('ravier_gate')}" style="width:240px;">
            <div id="treeToolBar" style="background:#fafafa;padding:2px;height:auto">
                <a id="btnAdd3" href="#" class="easyui-linkbutton"  onclick="switchTreeNode()" iconCls="icon-ok" plain="true">确定选中</a>
<!--                <a id="btnDel3" href="#" class="easyui-linkbutton"  onclick="export_xls()" iconCls="icon-xls" plain="true">导出报表</a>-->
                <a id="bz_export" href="#" class="easyui-linkbutton"  onclick="bz_xls()" iconCls="icon-xls" plain="true">泵站分公司报表</a>
            </div>
            <ul id="rivergateTree" class="easyui-tree"></ul>
        </div>
        <div data-options="region:'center'">
            <div class="easyui-tabs" id="tabCtrl" fit="true" border="false">
                <div title="河道闸门运行记录" fit=true  closable="false" style="padding:10px;">
                    <div id="subTabCtrl_1" class="easyui-tabs" fit="true" plain="true" >
<!--                        <div title="河道闸门基本信息" fit=true style="padding:10px;" href="__URL__/base_info" loadingMessage="{:LANG('loading')}"></div>-->
                        <div title="河道闸门运行记录" fit="true" style="padding:10px;" href="__URL__/log_show_gate_index" loadingMessage="{:LANG('loading')}" fit="true"></div>
                    </div>
                </div>

                <div title="雨情情况" closable="false"  style="padding:10px;">
                    <div class="easyui-tabs" fit="true" plain="true" style="height:100px;width:300px;">
                        <div title="雨情情况" style="padding:10px;" href="__URL__/log_show_weather_index" loadingMessage="{:LANG('loading')}" fit="true"></div>
                    </div>
                </div>


            </div>
        </div>

    </div>
    </div>
    <div id="gtx_window" class="easyui-window" closed="true" title="导出报表" data-options="modal:true" style="width:300px;height:250px;padding:0px;overflow: hidden;">
        <form id="form">
            <table class="form-table">
                <tr>
                    <td width="100" align="center">起始日期：</td>
                    <td><input id="start_date" class="easyui-datetimebox textbox" required data-options="validType:'md[\'10/11/2012\']',prompt:'{:LANG('pls_slet')}{:LANG('start_date')}'"></td>
                </tr>
                <tr>
                    <td width="100" align="center">结束日期：</td>
                    <td><input id="end_date" class="easyui-datetimebox textbox" required data-options="validType:'md[\'10/11/2012\']',prompt:'{:LANG('pls_slet')}{:LANG('end_date')}'"></td>
                </tr>
                <tr>
                    <td align="center" colspan="2">
                        <a href="javascript:export_excel()" class="easyui-linkbutton" style="width:120px">{:LANG('export')}</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div id="zb_window" class="easyui-window" closed="true" title="导出报表" data-options="modal:true" style="width:300px;height:300px;padding:0px;overflow: hidden;">
        <table class="form-table">
            <tr>
                <td width="100" align="center">起始日期：</td>
                <td><input id="start_date" class="easyui-datetimebox textbox" required data-options="validType:'md[\'10/11/2012\']',prompt:'{:LANG('pls_slet')}{:LANG('start_date')}'"></td>
            </tr>
            <tr>
                <td width="100" align="center">结束日期：</td>
                <td><input id="end_date" class="easyui-datetimebox textbox" required data-options="validType:'md[\'10/11/2012\']',prompt:'{:LANG('pls_slet')}{:LANG('end_date')}'"></td>
            </tr>
            <!--            <tr>-->
            <!--                <td align="center" colspan="2">-->
            <!--                    <a href="javascript:export_excel()" class="easyui-linkbutton" style="width:120px">{:LANG('export')}</a>-->
            <!--                </td>-->
            <!--            </tr>-->
        </table>
        <table class="form-table">
            <tr>
                <td align="center" colspan="2">
                    <a href="javascript:split_gate()" class="easyui-linkbutton" style="width:120px">闸门记录表</a>
                </td>
            </tr>
        </table>

    </div>
    </body>
</block>
<block name="footExtendJs">
    <script type="text/javascript">
        $(function(){

        });

        function split_gate(){
            var temp_ids = getChecked();
            export_gate(temp_ids);
//            temp_ids = temp_ids.split(",");
//            for(var i=0;i<temp_ids.length;i++){
//                export_gate(temp_ids[i]);
//            }
        }

        function export_gate(id){
            var start = $('#start_date').datetimebox('getValue');
            var end = $('#end_date').datetimebox('getValue');
            var url = '/Manage/AdminGate/export_record?pid='+id+'&start='+start+'&end='+end;
            window.open(url);
        }
    </script>
</block>
